﻿using System;
using System.Linq;
using System.Linq.Expressions;

namespace Model.Core {
    /// <summary>
    ///     数据操作实现接口
    /// </summary>
    /// <typeparam name="TModelEntity">The type of the T model entity.</typeparam>
    public interface IOperator<TModelEntity> : IDisposable
        where TModelEntity : class {
        /// <summary>
        ///     创建实体对象
        /// </summary>
        /// <param name="modelEntity">The model entity.</param>
        void Create(TModelEntity modelEntity);


        /// <summary>
        ///     读取实体对象
        /// </summary>
        /// <param name="id">Db Model's primary key</param>
        /// <returns>`0.</returns>
        TModelEntity Retrieve(Guid id);


        /// <summary>
        ///     更新实体对象
        /// </summary>
        /// <param name="modelEntity">The model entity.</param>
        void Modify(TModelEntity modelEntity);


        /// <summary>
        ///     删除实体对象
        /// </summary>
        /// <param name="modelEntity">Db Model's primary key</param>
        void Destroy(TModelEntity modelEntity);


        /// <summary>
        ///     自定义查询
        /// </summary>
        /// <returns>Linq 处理结果集</returns>
        IQueryable<TModelEntity> CreateQuery();

        /// <summary>
        ///     批量删除
        /// </summary>
        /// <param name="predicate"></param>
        void BatchDelete(Expression<Func<TModelEntity, bool>> predicate);

        /// <summary>
        ///     批量修改
        /// </summary>
        /// <param name="wherePredicate">查询条件</param>
        /// <param name="predicate">修改后的对象</param>
        void BatchUpdate(Expression<Func<TModelEntity, bool>> wherePredicate, Expression<Func<TModelEntity, TModelEntity>> predicate);

    }
}
